package operation;

import book.book;
import book.booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2022-11-18
 * Time: 20:38
 */
public class addoperation implements Ioper {

    @Override
    public void work(booklist book) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要添加的图书名");
        String name=scanner.nextLine();
        System.out.println("请输入作者名");
        String author=scanner.nextLine();
        System.out.println("请输入书的类型");
        String type=scanner.nextLine();
        System.out.println("请输入价格");
        int price=scanner.nextInt();
        book book1 = new book(name,author,type,price);
        int cur=book.getBookSize();
        for (int i = 0; i < cur; i++) {
            book book2=  book.getBooks(i);
           if(book2.getName().equals(name)){
               System.out.println("该书已经存在");
               break;
           }else {
               book.setBooks(book1);
               book.setBookSize(cur+1);
               System.out.println("图书添加成功");
               break;
           }
        }

    }
}
